package net.ruangtedy.android.latih.alert;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class AlertDialogActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		Button btnAlert=(Button) findViewById(R.id.btnAlert);
		Button btnAlert2Btn=(Button) findViewById(R.id.btnAlert2Btn);
		btnAlert2Btn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				alertTwoButton();
			}
		});
		
		btnAlert.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				alertOneButton();
			}
		});
		
	}

	public void alertOneButton(){
		AlertDialog alertDialog =new AlertDialog.Builder(this).create();
		alertDialog.setTitle("Alert Dialog");
		alertDialog.setMessage("Dear Android Alert");
		alertDialog.setIcon(R.drawable.tick);
		
		alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_SHORT).show();				
			}
		});
		
		alertDialog.show();
		
	}
	
	public void alertTwoButton(){
		AlertDialog alertDialog=new AlertDialog.Builder(this).create();
		alertDialog.setTitle("Confirm Delete");
		alertDialog.setMessage("Are you sure you want delete this?");
		alertDialog.setIcon(R.drawable.delete);
		
		alertDialog.setButton("yes", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				
			}
		});
		
		alertDialog.setButton2("NO", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				
			}
		});
		alertDialog.show();
		
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
